package com.letfox.auth.controller.auth;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.letfox.auth.controller.BaseController;
import com.letfox.auth.model.RegisterModel;
import com.letfox.auth.service.AuthService;
import com.letfox.common.model.ResultResponse;

@Controller
@RequestMapping(value = "/auth")
public class AuthController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private AuthService authService;

	/**
	 * 登录
	 * @param account 账号
	 * @param password 密码
	 * @return ResultResponse
	 */
	@RequestMapping(value = "/login",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse login(@RequestParam(value = "account") String account, String password) {
		try {
			resultResponse = authService.authLogin(account, password);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return resultResponse;
	}
	
	/**
	 * 注册
	 * @param account 账号
	 * @param password 密码
	 * @return ResultResponse
	 */
	@RequestMapping(value = "/register",method=RequestMethod.POST)
	@ResponseBody
	public ResultResponse register(@ModelAttribute RegisterModel registerModel) {
		try{
			//注册
			resultResponse = authService.registerAccount(registerModel);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return resultResponse;
	}
}
